from PIL import Image, ImageDraw, ImageFont

# 设置画布大小和颜色
img = Image.new('RGB', (500, 300), color='white')
draw = ImageDraw.Draw(img)

# 定义字体
font = ImageFont.load_default()

# 绘制分数及计算过程
draw.text((10, 10), "分数计算: 1/2 + 1/3", fill="black", font=font)
draw.text((10, 40), "通分后: 3/6 + 2/6", fill="black", font=font)
draw.text((10, 70), "和: 5/6", fill="black", font=font)

# 绘制装饰图形
draw.line((10, 100, 490, 100), fill="black", width=2)
draw.text((10, 120), "差: 1/6", fill="black", font=font)

# 保存图像
img_path = "fraction_calculation.png"
img.save(img_path)
print(f"图形已保存为 {img_path}")